package threading;


import java.util.concurrent.atomic.AtomicInteger;

public class ThreadDemo24 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num = new AtomicInteger(0);
        Thread t1 = new Thread(()->{
            for(int i = 0;i<50000;i++){
                //num++
                num.getAndIncrement();
                //++num
//                num.incrementAndGet();
//                //--num
//                num.decrementAndGet();
//                //num--
//                num.getAndDecrement();
            }
        });
        Thread t2 = new Thread(()->{
           for(int i=0;i<50000;i++){
               num.getAndIncrement();
           }
        });
        t1.start();
        t2.start();

        t1.join();//阻塞等待
        t2.join();

        //get 获取到数值
        System.out.println(num.get());
    }
}
